package forces;

import physicalobjects.Mass;
import simulationhandlers.Simulation;

/**
 * This is the wall force.
 *
 * @author Kathleen Lan, Seon Kang
 */

public class WallForce extends Force {
    private static double ourDEFAULTMAGNITUDE = 1;
    private static double ourDEFAULTEXPONENT = 2;
    private static final double QUARTERROTATION = 90;
    private static final double HALFROTATION = 180;
    private static final int WALLTHREEID = 3;
    private static final int WALLFOURID = 4;

    private int myWallID;
    private double myExponent;
    private Simulation mySimulation;

 // either equal to DEFAULT_MAGNITUDE or
    // magnitude inputed from Environmental data
    // file
 // current magnitude (equals 0 when
    // CenterOfMass is toggled off,
    private String myForceName = "wall";

    /**
     * 
     * @param id 
     */
    public WallForce (int id) {
        super(HALFROTATION - (id * QUARTERROTATION), ourDEFAULTMAGNITUDE);
        setMyName(myForceName + id);
        myExponent = ourDEFAULTEXPONENT;
    }

    /**
     * 
     * @param id 
     * @param magnitude 
     * @param exponent 
     * @param sim 
     */
    public WallForce (int id, double magnitude, double exponent, Simulation sim) {
        super(HALFROTATION - (id * QUARTERROTATION), ourDEFAULTMAGNITUDE);
        setMyName(myForceName + id);
        myExponent = exponent;
        myWallID = id;
        mySimulation = sim;

    }

    /**
     * 
     * @param m 
     * @return
     */
    public double getDistanceFromWall (Mass m) {
        if (myWallID == 1) {
            return m.getCenter().getY();
        }
        else if (myWallID == 2) {
            return mySimulation.getSize().width - m.getCenter().getX();
        }
        else if (myWallID == WALLTHREEID) {
            return mySimulation.getSize().height - m.getCenter().getY();
        }
        else if (myWallID == WALLFOURID) {
            return m.getCenter().getX();
        }
        return 0;
    }

    @Override
    public void update (Mass m) {
        setDirection(HALFROTATION + (myWallID * QUARTERROTATION));
        setMagnitude(getMagnitude() *
                Math.pow(getDistanceFromWall(m), myExponent));
        m.applyForce(this);
    }
}
